/**
 * @file 能量项链
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @brief
 * @version 1.0
 * @date 2022-05-11
 *
 * @copyright Copyright (c) 2022
 *
 **/

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int w[N * 2];
int dp[N * 2][N * 2];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> w[i], w[i + n] = w[i];

  for (int len = 2; len <= n + 1; ++len) {
    for (int i = 1; i + len - 1 <= n * 2; ++i) {
      int j = i + len - 1;
      if (len == 2)
        dp[i][j] = 0;
      else {
        for (int k = i + 1; k < j; ++k) {
          dp[i][j] = max({dp[i][j], dp[i][k] + dp[k][j] + w[i] * w[k] * w[j]});
        }
      }
    }
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) res = max(res, dp[i][i + n]);
  cout << res << endl;
}
